package com.springframework.common;

import com.self.springframework.beans.factory.config.BeanPostProcessor;
import com.springframework.bean.UserService;

public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        if ("userService".equals(beanName)){
            UserService userService = (UserService) bean;
            userService.setName("金三胖");
            return userService;
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        if ("userService".equals(beanName)){
            UserService userService = (UserService) bean;
            userService.setUserDao(null);
            return userService;
        }
        return bean;
    }
}
